<template>
  <div class="form">
    <el-form
      :inline="true"
      :label-suffix="labelSuffix"
      :label-width="labelWidth"
      :size="size"
      :model="model"
      ref="form"
    >
      <slot></slot>
      <div v-show="hidden">
        <slot name="hidden"> </slot>
      </div>
    </el-form>
    <el-button type="primary" @click="search" :size="size"> 查询 </el-button>
    <el-button type="default" @click="reset" :size="size"> 清空 </el-button>
    <el-button type="primary" @click="expend" :size="size" class="collapse">
      <el-icon style="transform: rotate(90deg)">
        <MoreFilled />
      </el-icon>
      {{ hidden ? '折叠' : '更多条件' }}
    </el-button>
    <slot name="append"> </slot>
  </div>
</template>

<script>
import { defineComponent } from 'vue'
import { Search, Refresh, MoreFilled } from '@element-plus/icons-vue'
export default defineComponent({
  props: {
    size: {
      type: String,
      default: 'small'
    },
    // 隐藏 清除筛选条件
    hideClean: {
      type: Boolean,
      default: false
    },
    // 在清空筛选条件后提交
    submitAfterReset: {
      type: Boolean,
      default: false
    },
    labelWidth: {
      type: String,
      default: '100px'
    },
    model: {
      type: Object,
      default: () => {}
    },
    labelSuffix: {
      type: String,
      default: ''
    }
  },
  emits: ['search', 'reset'],
  data() {
    return {
      collapse: false,
      hidden: false
    }
  },
  methods: {
    search() {
      this.$emit('search')
    },
    reset() {
      this.$emit('reset')
      if (this.submitAfterReset) {
        this.$emit('search')
      }
    },
    expend() {
      this.hidden = !this.hidden
    }
  }
})
</script>

<style lang="scss" scoped>
.form {
  :deep(.el-form-item) {
    margin-right: 0;
    margin-bottom: 0;
    width: 100%;
    .el-form-item__label {
      color: #000000d8;
      font-family: PingFang SC;
      font-weight: 400;
      font-size: 12px;
      line-height: 24px;
      letter-spacing: 0px;
      padding-right: 4px;
    }
  }
  :deep(.el-row) {
    margin-bottom: 8px;
    padding-right: 16px;
  }
}
.collapse {
  transition: all 0.5s ease;
}
</style>
